home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
ICMPSUBR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-13
|
1KB
|
54 lines
/* Low-level routines for ICMP */
#include "global.h"
#include "mbuf.h"
#include "internet.h"
#include "icmp.h"
/* Generate ICMP header in network byte order, link data, compute checksum */
struct mbuf *
htonicmp(icmp,data)
struct icmp *icmp;
struct mbuf *data;
{
struct mbuf *bp;
register char *cp;
int16 checksum;
if((bp = pushdown(data,ICMPLEN)) == NULLBUF)
return NULLBUF;
cp = bp->data;
*cp++ = icmp->type;
*cp++ = icmp->code;
cp = put16(cp,0); /* Clear checksum */
cp = put16(cp,icmp->args.echo.id);
cp = put16(cp,icmp->args.echo.seq);
/* Compute checksum, and stash result */
checksum = cksum(NULLHEADER,bp,len_mbuf(bp));
cp = &bp->data[2];
cp = put16(cp,checksum);
return bp;
}
/* Pull off ICMP header */
int
ntohicmp(icmp,bpp)
struct icmp *icmp;
struct mbuf **bpp;
{
char icmphead[8];
#ifdef DEBUG
if(icmp == (struct icmp *)NULL)
return -1;
#endif
pullup(bpp,icmphead,8);
icmp->type = icmphead[0];
icmp->code = icmphead[1];
icmp->args.echo.id = get16(icmphead + 4);
icmp->args.echo.seq = get16(icmphead + 6);
return 0;
}